<article id="wikiArticle">
<div></div>
<p>本对象代表了一个关于 <a href="/en/Core_JavaScript_1.5_Reference/Global_Functions/eval" title="en/Core_JavaScript_1.5_Reference/Global_Functions/eval">eval</a> 函数的错误.此异常不再会被JavaScript抛出，但是EvalError对象仍然保持兼容性.</p>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre><code class="language-javascript"><code>new EvalError([<var>message</var>[, <var>fileName</var>[, <var>lineNumber</var>]]])</code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<dl>
<dt>message</dt>
<dd>可选参数.人类可阅读的关于错误的描述.</dd>
</dl>
<dl>
<dt>fileName(非标准)</dt>
<dd>可选参数.代码中导致异常的文件的文件名.</dd>
</dl>
<dl>
<dt>lineNumber(非标准)</dt>
<dd>可选参数.代码中导致异常的代码的行号.</dd>
</dl>
<h2 id="Properties" name="Properties">属性</h2>
<dl>
<dt><a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/EvalError/prototype" title="en/Core_JavaScript_1.5_Reference/Global_Objects/EvalError/prototype">prototype</a></dt>
<dd>允许向EvalError对象中添加自定义属性.</dd>
</dl>
<h2 id="Methods" name="Methods">方法</h2>
<p>全局的EvalError对象本身不包含任何方法, 然而它通过原型链继承了一些方法.</p>
<h2 id="EvalError_实例"><code>EvalError</code> 实例</h2>
<h3 id="属性">属性</h3>
<p></p><dl>
<dt><code>EvalError.prototype.constructor</code></dt>
<dd>指定创建实例原型的函数.</dd>
<dt><a href="Reference/Global_Objects/Error/message" title="message 属性是有关错误信息，人类易读的（human-readable）描述。"><code>EvalError.prototype.message</code></a></dt>
<dd>错误信息. 从 ECMA-262 开始 <a href="Reference/Global_Objects/EvalError" title="本对象代表了一个关于 eval 函数的错误.此异常不再会被JavaScript抛出，但是EvalError对象仍然保持兼容性."><code>EvalError</code></a> 提供 <code>message</code> （继承自<a href="Reference/Global_Objects/Error/message" title="message 属性是有关错误信息，人类易读的（human-readable）描述。"><code>Error.prototype.message</code></a>）属性, 详见 <a href="/en-US/docs/Mozilla/Projects/SpiderMonkey">SpiderMonkey</a>.</dd>
<dt><a href="Reference/Global_Objects/Error/name" title='name 属性表示error类型的名称.初始值为"Error".'><code>EvalError.prototype.name</code></a></dt>
<dd>错误名称.继承自 <a href="Reference/Global_Objects/Error" title="通过Error的构造器可以创建一个错误对象。当运行时错误产生时，Error的实例对象会被抛出。Error对象也可用于用户自定义的异常的基础对象。下面列出了各种内建的标准错误类型。"><code>Error</code></a>.</dd>
<dt><a href="Reference/Global_Objects/Error/fileName" title="fileName 属性包含引发此错误的文件的路径."><code>EvalError.prototype.fileName</code></a></dt>
<dd>引发错误的文件路径. 继承自 <a href="Reference/Global_Objects/Error" title="通过Error的构造器可以创建一个错误对象。当运行时错误产生时，Error的实例对象会被抛出。Error对象也可用于用户自定义的异常的基础对象。下面列出了各种内建的标准错误类型。"><code>Error</code></a>.</dd>
<dt><a href="Reference/Global_Objects/Error/lineNumber" title="lineNumber 属性的值为抛出错误的代码在其源文件中所在的行号。"><code>EvalError.prototype.lineNumber</code></a></dt>
<dd>引发错误所在行.继承自 <a href="Reference/Global_Objects/Error" title="通过Error的构造器可以创建一个错误对象。当运行时错误产生时，Error的实例对象会被抛出。Error对象也可用于用户自定义的异常的基础对象。下面列出了各种内建的标准错误类型。"><code>Error</code></a>.</dd>
<dt><a href="Reference/Global_Objects/Error/columnNumber" title="columnNumber属性包含引发此错误的文件行中的列号。"><code>EvalError.prototype.columnNumber</code></a></dt>
<dd>引发错误所在的列. 继承自<a href="Reference/Global_Objects/Error" title="通过Error的构造器可以创建一个错误对象。当运行时错误产生时，Error的实例对象会被抛出。Error对象也可用于用户自定义的异常的基础对象。下面列出了各种内建的标准错误类型。"><code>Error</code></a>.</dd>
<dt><a href="Reference/Global_Objects/Error/stack" title="Error对象作为一个非标准的栈属性提供了一种函数追踪方式。无论这个函数被被调用，处于什么模式，来自于哪一行或者哪个文件，有着什么样的参数。这个栈产生于最近一次调用最早的那次调用，返回原始的全局作用域调用"><code>EvalError.prototype.stack</code></a></dt>
<dd>堆栈.继承自 <a href="Reference/Global_Objects/Error" title="通过Error的构造器可以创建一个错误对象。当运行时错误产生时，Error的实例对象会被抛出。Error对象也可用于用户自定义的异常的基础对象。下面列出了各种内建的标准错误类型。"><code>Error</code></a>.</dd>
</dl><p></p>
<h3 id="方法">方法</h3>
<p></p><p>虽然 <a href="Reference/Global_Objects/EvalError" title="本对象代表了一个关于 eval 函数的错误.此异常不再会被JavaScript抛出，但是EvalError对象仍然保持兼容性."><code>EvalError</code></a> 自己的属性方法较少, 但是通过原型链继承了很多有用的方法.</p><p></p>
<h2 id="例子">例子</h2>
<p><code>EvalError</code> 不在当前ECMAScript规范中使用，因此不会被运行时抛出. 但是对象本身仍然与规范的早期版本向后兼容.</p>
<h3 id="创建_EvalError">创建 <code>EvalError</code></h3>
<pre><code>try {
  throw new EvalError('Hello', 'someFile.js', 10);
} catch (e) {
  console.log(e instanceof EvalError); // true
  console.log(e.message);              // "Hello"
  console.log(e.name);                 // "EvalError"
  console.log(e.fileName);             // "someFile.js"
  console.log(e.lineNumber);           // 10
  console.log(e.columnNumber);         // 0
  console.log(e.stack);                // "@Scratchpad/2:2:9\n"
}</code></code></pre>
<h2 id="规范">规范</h2>
<table>
<tbody>
<tr>
<th scope="col">规范</th>
<th scope="col">状态</th>
<th scope="col">注释</th>
</tr>
<tr>
<td><a class="external" href="https://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%203rd%20edition,%20December%201999.pdf" hreflang="en" lang="en" rel="noopener" title="ECMAScript 3rd Edition (ECMA-262)">ECMAScript 3rd Edition (ECMA-262)</a></td>
<td><span class="spec-Standard">Standard</span></td>
<td>初始定义.</td>
</tr>
<tr>
<td><a class="external" href="https://www.ecma-international.org/ecma-262/5.1/#sec-15.11.6.1" hreflang="en" lang="en" rel="noopener">ECMAScript 5.1 (ECMA-262)<br/><small lang="zh-CN">EvalError</small></a></td>
<td><span class="spec-Standard">Standard</span></td>
<td>本规范中未使用. 为了保持向后兼容.</td>
</tr>
<tr>
<td><a class="external" href="https://www.ecma-international.org/ecma-262/6.0/#sec-native-error-types-used-in-this-standard-evalerror" hreflang="en" lang="en" rel="noopener">ECMAScript 2015 (6th Edition, ECMA-262)<br/><small lang="zh-CN">EvalError</small></a></td>
<td><span class="spec-Standard">Standard</span></td>
<td>本规范中未使用. 为了保持向后兼容.</td>
</tr>
<tr>
<td><a class="external" href="https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-evalerror" hreflang="en" lang="en" rel="noopener">ECMAScript Latest Draft (ECMA-262)<br/><small lang="zh-CN">EvalError</small></a></td>
<td><span class="spec-Draft">Draft</span></td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<div class="hidden">
<p>该页面中的兼容性表格由结构化的数据生成。如果有意向贡献数据，请查看 <a class="external" href="https://github.com/mdn/browser-compat-data" rel="noopener">https://github.com/mdn/browser-compat-data</a> 并发起 pull request。</p>
</div>
<p></p><div class="bc-data"><a class="bc-github-link external" href="https://github.com/mdn/browser-compat-data" rel="noopener">Update compatibility data on GitHub</a><table class="bc-table bc-table-js"><thead><tr class="bc-platforms"><td></td><th class="bc-platform-desktop" colspan="6"><span>Desktop</span></th><th class="bc-platform-mobile" colspan="7"><span>Mobile</span></th><th class="bc-platform-server" colspan="1"><span>Server</span></th></tr><tr class="bc-browsers"><td></td><th class="bc-browser-chrome"><span class="bc-head-txt-label bc-head-icon-chrome">Chrome</span></th><th class="bc-browser-edge"><span class="bc-head-txt-label bc-head-icon-edge">Edge</span></th><th class="bc-browser-firefox"><span class="bc-head-txt-label bc-head-icon-firefox">Firefox</span></th><th class="bc-browser-ie"><span class="bc-head-txt-label bc-head-icon-ie">Internet Explorer</span></th><th class="bc-browser-opera"><span class="bc-head-txt-label bc-head-icon-opera">Opera</span></th><th class="bc-browser-safari"><span class="bc-head-txt-label bc-head-icon-safari">Safari</span></th><th class="bc-browser-webview_android"><span class="bc-head-txt-label bc-head-icon-webview_android">Android webview</span></th><th class="bc-browser-chrome_android"><span class="bc-head-txt-label bc-head-icon-chrome_android">Chrome for Android</span></th><th class="bc-browser-edge_mobile"><span class="bc-head-txt-label bc-head-icon-edge_mobile">Edge Mobile</span></th><th class="bc-browser-firefox_android"><span class="bc-head-txt-label bc-head-icon-firefox_android">Firefox for Android</span></th><th class="bc-browser-opera_android"><span class="bc-head-txt-label bc-head-icon-opera_android">Opera for Android</span></th><th class="bc-browser-safari_ios"><span class="bc-head-txt-label bc-head-icon-safari_ios">Safari on iOS</span></th><th class="bc-browser-samsunginternet_android"><span class="bc-head-txt-label bc-head-icon-samsunginternet_android">Samsung Internet</span></th><th class="bc-browser-nodejs"><span class="bc-head-txt-label bc-head-icon-nodejs">Node.js</span></th></tr></thead><tbody><tr><th scope="row"><code>EvalError</code></th><td class="bc-supports-yes bc-browser-chrome"><span class="bc-browser-name">Chrome</span><abbr class="bc-level-yes only-icon" title="Full support">
<span>Full support</span>
</abbr>
              Yes</td><td class="bc-supports-yes bc-browser-edge"><span class="bc-browser-name">Edge</span><abbr class="bc-level-yes only-icon" title="Full support">
<span>Full support</span>
</abbr>
              12</td><td class="bc-supports-yes bc-browser-firefox"><span class="bc-browser-name">Firefox</span><abbr class="bc-level-yes only-icon" title="Full support">
<span>Full support</span>
</abbr>
              1</td><td class="bc-supports-yes bc-browser-ie"><span class="bc-browser-name">IE</span><abbr class="bc-level-yes only-icon" title="Full support">
<span>Full support</span>
</abbr>
              Yes</td><td class="bc-supports-yes bc-browser-opera"><span class="bc-browser-name">Opera</span><abbr class="bc-level-yes only-icon" title="Full support">
<span>Full support</span>
</abbr>
              Yes</td><td class="bc-supports-yes bc-browser-safari"><span class="bc-browser-name">Safari</span><abbr class="bc-level-yes only-icon" title="Full support">
<span>Full support</span>
</abbr>
              Yes</td><td class="bc-supports-yes bc-browser-webview_android"><span class="bc-browser-name">WebView Android</span><abbr class="bc-level-yes only-icon" title="Full support">
<span>Full support</span>
</abbr>
              Yes</td><td class="bc-supports-yes bc-browser-chrome_android"><span class="bc-browser-name">Chrome Android</span><abbr class="bc-level-yes only-icon" title="Full support">
<span>Full support</span>
</abbr>
              Yes</td><td class="bc-supports-yes bc-browser-edge_mobile"><span class="bc-browser-name">Edge Mobile</span><abbr class="bc-level-yes only-icon" title="Full support">
<span>Full support</span>
</abbr>
              Yes</td><td class="bc-supports-yes bc-browser-firefox_android"><span class="bc-browser-name">Firefox Android</span><abbr class="bc-level-yes only-icon" title="Full support">
<span>Full support</span>
</abbr>
              4</td><td class="bc-supports-yes bc-browser-opera_android"><span class="bc-browser-name">Opera Android</span><abbr class="bc-level-yes only-icon" title="Full support">
<span>Full support</span>
</abbr>
              Yes</td><td class="bc-supports-yes bc-browser-safari_ios"><span class="bc-browser-name">Safari iOS</span><abbr class="bc-level-yes only-icon" title="Full support">
<span>Full support</span>
</abbr>
              Yes</td><td class="bc-supports-yes bc-browser-samsunginternet_android"><span class="bc-browser-name">Samsung Internet Android</span><abbr class="bc-level-yes only-icon" title="Full support">
<span>Full support</span>
</abbr>
              Yes</td><td class="bc-supports-yes bc-browser-nodejs"><span class="bc-browser-name">nodejs</span><abbr class="bc-level-yes only-icon" title="Full support">
<span>Full support</span>
</abbr>
              Yes</td></tr></tbody></table><section class="bc-legend" id="sect1"><h3 class="offscreen" id="Legend">Legend</h3><dl><dt><span class="bc-supports-yes bc-supports">
<abbr class="bc-level bc-level-yes only-icon" title="Full support">
<span>Full support</span>
                  
                </abbr></span></dt><dd>Full support</dd></dl></section></div><p></p>
<h2 id="相关链接">相关链接</h2>
<ul>
<li><a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Error" title="en/Core_JavaScript_1.5_Reference/Global_Objects/Error">Error</a></li>
<li><a href="/en/Core_JavaScript_1.5_Reference/Global_Functions/eval" title="en/Core_JavaScript_1.5_Reference/Global_Functions/eval">eval</a></li>
<li><a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/EvalError/prototype" title="en/Core_JavaScript_1.5_Reference/Global_Objects/EvalError/prototype">EvalError.prototype</a></li>
</ul>
</article>